package com.hxzy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hxzy.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import javax.validation.Valid;

@Mapper
@Repository
public interface ShoppingCartMapper extends BaseMapper<ShoppingCart> {


    ShoppingCart selectByPrimaryKey(Long id);

    /**
     * 根据商品ID和用户ID查询购物车的数据
     * @param userId 用户ID
     * @param dishId 商品ID
     * @return
     */
    ShoppingCart findByUserIdAndDishId(@Param(value = "userId") Long userId, @Param(value = "dishId") Long dishId);

    /**
     * 更新购物车的数量
     * @param id
     * @param num 数量
     * @return
     */
    @Update(value = "update shopping_cart set number=#{num} where id=#{id}")
    int updateCartNumber(@Param(value = "id") Long id, @Param(value = "num") int num);

    /**
     * 清除当前商家的购物车
     * @param merchantId
     */
    @Delete(value = "delete from shopping_cart where user_id=#{userId} and merchant_id=#{merchantId} ")
    int clean(@Param(value = "userId") Long userId,@Param(value = "merchantId") Long merchantId);

}